/*******************************************
Module: zt_atom.h
E-Mail: 24zhutian@gmail.com
Notices: Copyright (c) 2007-2011 ls
*******************************************/
#ifndef zt_atom_h
#define zt_atom_h

#ifdef __cplusplus
extern "C" {
#endif

typedef struct zt_lock_s{
#ifdef _MSC_VER
	CRITICAL_SECTION obj;
#else
	pthread_mutex_t obj;
#endif
}zt_lock_t;

#ifdef _MSC_VER
#define zt_lock_init(l)		InitializeCriticalSection(&((l)->obj))
#define zt_lock_clear(l)	DeleteCriticalSection(&((l)->obj))
#define zt_lock_lock(l)		EnterCriticalSection(&((l)->obj))
#define zt_lock_unlock(l)	LeaveCriticalSection(&((l)->obj))
#else
#define zt_lock_init(l)		((l)->obj=PTHREAD_MUTEX_INITIALIZER)
#define zt_lock_clear(l)	((l)->obj=PTHREAD_MUTEX_INITIALIZER)
#define zt_lock_lock(l)		pthread_mutex_lock(&((l)->obj))
#define zt_lock_unlock(l)	pthread_mutex_unlock(&((l)->obj))
#endif

#ifdef __cplusplus
}
#endif /* C++ */
#endif /* zt_atom_h */
